package com.cskaoyan.day31.work1._04_proxy._02_dynamic_proxy._00_reflect;

import com.cskaoyan.day31.work1._04_proxy._00_bean.Study;
import com.cskaoyan.day31.work1._04_proxy._00_bean.User;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectApplication {
    public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        normal();

        reflect();
        reflect2();
    }



    private static void normal(){
        User user = new User();
        user.buyBreakfast("热干面");
    }

    private static void reflect() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<User> userClass = User.class;
        User user = userClass.getConstructor().newInstance();
        Method method = userClass.getDeclaredMethod("buyBreakfast", String.class);
        String arg = "热干面";
        Object result = method.invoke(user, arg);
    }

    private static void reflect2() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        User user = new User();
        Method method = Study.class.getDeclaredMethod("study", String.class, String.class);
        Object[] args = new Object[]{"Java","PHP"};
        Object result = method.invoke(user, args);
        System.out.println("result = " + result);
    }

}
